package jsu.lipengcheng.trafficnet.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jsu.lipengcheng.trafficnet.common.BeanThread;
import jsu.lipengcheng.trafficnet.common.PageResult;
import jsu.lipengcheng.trafficnet.mapper.CarMapper;
import jsu.lipengcheng.trafficnet.pojo.Cars;
import jsu.lipengcheng.trafficnet.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService {
    @Autowired
    private CarMapper carMapper;

    /**
     * 查询用户的所有车辆
     * @return
     */
    public List<Cars> selectcar() {
        Integer id = BeanThread.get();
        List<Cars> carsList= carMapper.selectbyuserid(id);
        return carsList;
    }

    /**
     * 根据id查询用户汽车
     * @param id
     * @return
     */
    public Cars selectbyid(int id) {
        Cars cars = carMapper.selectById(id);
        return cars;
    }

    /**
     * 分页查询所有用户汽车
     * @param page
     * @param pageSize
     * @param status
     * @param userid
     * @return
     */
    public PageResult selectcarall(int page, int pageSize, Integer status, Integer userid) {
        PageHelper.startPage(page,pageSize);
        List<Cars> carsList= carMapper.selectpages(status,userid);
        Page<Cars> carsPage =(Page<Cars>) carsList;
        PageResult pageResult = new PageResult(carsPage.getTotal(),carsPage.getResult());
        return pageResult;
    }

    /**
     * 添加车辆
     * @param cars
     */
    public void insert(Cars cars) {
        carMapper.insert(cars);
    }

    /**
     * 修改车辆
     * @param cars
     */
    public void update(Cars cars) {
        carMapper.updateById(cars);
    }

    /**
     * 删除车俩
     * @param id
     */
    public void deletecar(int id) {
        carMapper.deleteById(id);
    }

    @Override
    public List<Cars> selectall() {
        Integer id = BeanThread.get();
        return carMapper.selectbyuserid(id);
    }

}
